import Mock from "mockjs"

// 模拟登录接口
Mock.mock("/api/login", "post", (options) => {
  const { username, password } = JSON.parse(options.body)

  if (username === "admin" && password === "admin123") {
    return {
      success: true,
      token: "mock-token-123456789",
      message: "登录成功",
    }
  } else {
    return {
      success: false,
      message: "用户名或密码错误",
    }
  }
})

// 模拟统计数据接口
Mock.mock("/api/statistics", "get", () => {
  return {
    totalCustomers: Mock.Random.integer(100, 500),
    monthlyEvents: Mock.Random.integer(10, 50),
    monthlyRevenue: Mock.Random.float(10, 100, 2, 2),
    totalStaff: Mock.Random.integer(20, 100),
    revenueProgress: {
      current: Mock.Random.float(30, 80, 2, 2),
      target: 100,
    },
    customerProgress: {
      current: Mock.Random.integer(15, 45),
      target: 50,
    },
    eventProgress: {
      current: Mock.Random.integer(8, 18),
      target: 20,
    },
  }
})

// 模拟近期婚礼活动接口
Mock.mock("/api/events/recent", "get", () => {
  const events = []
  const statuses = ["pending", "confirmed", "completed", "canceled"]

  for (let i = 0; i < 5; i++) {
    events.push({
      id: Mock.Random.guid(),
      name: `${Mock.Random.word(4, 8)}婚礼`,
      customer: Mock.Random.cname(),
      date: Mock.Random.date("yyyy-MM-dd"),
      venue: `${Mock.Random.city()}${Mock.Random.word(2, 5)}酒店`,
      status: statuses[Mock.Random.integer(0, 3)],
    })
  }

  return events
})

// 模拟客户列表接口
Mock.mock("/api/customers", "get", () => {
  const customers = []
  const statuses = ["potential", "confirmed", "completed", "canceled"]
  const budgets = ["10-20", "20-50", "50-100", "100+"]

  for (let i = 0; i < 20; i++) {
    customers.push({
      id: Mock.Random.guid(),
      name: Mock.Random.cname(),
      phone: Mock.mock(/^1[3-9]\d{9}$/),
      email: Mock.Random.email(),
      weddingDate: Mock.Random.date("yyyy-MM-dd"),
      budget: budgets[Mock.Random.integer(0, 3)],
      status: statuses[Mock.Random.integer(0, 3)],
      notes: Mock.Random.paragraph(1),
    })
  }

  return customers
})

// 模拟添加客户接口
Mock.mock("/api/customers", "post", (options) => {
  console.log("添加客户:", JSON.parse(options.body))
  return {
    success: true,
    message: "客户添加成功",
  }
})

// 模拟更新客户接口
Mock.mock(/\/api\/customers\/.*/, "put", (options) => {
  console.log("更新客户:", JSON.parse(options.body))
  return {
    success: true,
    message: "客户更新成功",
  }
})

// 模拟删除客户接口
Mock.mock(/\/api\/customers\/.*/, "delete", () => {
  return {
    success: true,
    message: "客户删除成功",
  }
})

// 模拟婚礼活动列表接口
Mock.mock("/api/events", "get", () => {
  const events = []
  const statuses = ["pending", "confirmed", "inProgress", "completed", "canceled"]
  const types = ["standard", "luxury", "simple", "theme"]

  for (let i = 0; i < 15; i++) {
    events.push({
      id: Mock.Random.guid(),
      name: `${Mock.Random.word(4, 8)}婚礼`,
      customer: Mock.Random.cname(),
      customerId: Mock.Random.guid(),
      date: Mock.Random.date("yyyy-MM-dd"),
      time: Mock.Random.time("HH:mm"),
      venue: `${Mock.Random.city()}${Mock.Random.word(2, 5)}酒店`,
      budget: Mock.Random.integer(10, 200),
      status: statuses[Mock.Random.integer(0, 4)],
      type: types[Mock.Random.integer(0, 3)],
      description: Mock.Random.paragraph(1),
    })
  }

  return events
})

// 模拟添加婚礼活动接口
Mock.mock("/api/events", "post", (options) => {
  console.log("添加婚礼活动:", JSON.parse(options.body))
  return {
    success: true,
    message: "婚礼活动添加成功",
  }
})

// 模拟更新婚礼活动接口
Mock.mock(/\/api\/events\/.*/, "put", (options) => {
  console.log("更新婚礼活动:", JSON.parse(options.body))
  return {
    success: true,
    message: "婚礼活动更新成功",
  }
})

// 模拟删除婚礼活动接口
Mock.mock(/\/api\/events\/.*/, "delete", () => {
  return {
    success: true,
    message: "婚礼活动删除成功",
  }
})

// 模拟员工列表接口
Mock.mock("/api/staff", "get", () => {
  const staff = []
  const positions = ["manager", "planner", "coordinator", "designer", "photographer", "assistant"]
  const departments = ["planning", "design", "photography", "coordination", "finance", "admin"]
  const statuses = ["active", "leave", "resigned"]

  for (let i = 0; i < 20; i++) {
    const position = positions[Mock.Random.integer(0, 5)]
    const department = departments[Mock.Random.integer(0, 5)]

    let positionName = ""
    switch (position) {
      case "manager":
        positionName = "婚礼策划经理"
        break
      case "planner":
        positionName = "婚礼策划师"
        break
      case "coordinator":
        positionName = "婚礼协调员"
        break
      case "designer":
        positionName = "婚礼设计师"
        break
      case "photographer":
        positionName = "婚礼摄影师"
        break
      case "assistant":
        positionName = "婚礼助理"
        break
      default:
        positionName = position
    }

    let departmentName = ""
    switch (department) {
      case "planning":
        departmentName = "策划部"
        break
      case "design":
        departmentName = "设计部"
        break
      case "photography":
        departmentName = "摄影部"
        break
      case "coordination":
        departmentName = "协调部"
        break
      case "finance":
        departmentName = "财务部"
        break
      case "admin":
        departmentName = "行政部"
        break
      default:
        departmentName = department
    }

    staff.push({
      id: Mock.Random.guid(),
      name: Mock.Random.cname(),
      avatar: null,
      position: positionName,
      department: departmentName,
      phone: Mock.mock(/^1[3-9]\d{9}$/),
      email: Mock.Random.email(),
      idNumber: Mock.mock(/^\d{18}$/),
      joinDate: Mock.Random.date("yyyy-MM-dd"),
      birthday: Mock.Random.date("yyyy-MM-dd"),
      status: statuses[Mock.Random.integer(0, 2)],
      salary: Mock.Random.integer(5000, 20000),
      address: `${Mock.Random.province()}${Mock.Random.city()}${Mock.Random.county()}${Mock.Random.word(5, 10)}`,
      notes: Mock.Random.paragraph(1),
    })
  }

  return staff
})

// 模拟添加员工接口
Mock.mock("/api/staff", "post", (options) => {
  console.log("添加员工:", JSON.parse(options.body))
  return {
    success: true,
    message: "员工添加成功",
  }
})

// 模拟更新员工接口
Mock.mock(/\/api\/staff\/.*/, "put", (options) => {
  console.log("更新员工:", JSON.parse(options.body))
  return {
    success: true,
    message: "员工更新成功",
  }
})

// 模拟删除员工接口
Mock.mock(/\/api\/staff\/.*/, "delete", () => {
  return {
    success: true,
    message: "员工删除成功",
  }
})

